import type { Permission } from '@/types/rbac'

// 将权限树转换为菜单结构，只包含类型为menu的权限项
export function transformPermissionsToMenu(permissions: Permission[]): any[] {
  return permissions
    .filter((permission) => permission.type === 'menu') // 只包含类型为menu的权限
    .map((permission) => {
      const menuItem: any = {
        label: permission.label,
        icon: permission.icon || 'fa-solid fa-circle',
      }

      if (permission.path) {
        menuItem.path = permission.path
      }

      if (permission.children && permission.children.length > 0) {
        // 递归处理子菜单时也应用相同的过滤条件
        menuItem.children = transformPermissionsToMenu(permission.children)
      }

      return menuItem
    })
}
